﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ChuyenDongVatLy
{
    public partial class frMPN : Form
    {
        public frMPN()
        {
            InitializeComponent();
        }
        public delegate void GetString(string gocnghieng,string chieudai,bool createForm);
        public GetString GetMyValue;
        public delegate void GetString2(bool createfrom);
        public GetString2 GetMyValue2;

        private void btnOK_Click(object sender, EventArgs e)
        {


            if (tbxChieuDai.Text == "" || tbxGocNghieng.Text == "")
            {
                MessageBox.Show("Ban phai dien day du thong tin!");
            }
            else
            {
                float f = float.Parse(tbxGocNghieng.Text);
                float d = float.Parse(tbxChieuDai.Text);
                if (f < 0 || f > 0.4 || d < 50 || d > 200)
                {
                    if (f < 0 || f > 0.4)
                        MessageBox.Show("Góc nghiêng không nằm trong khoảng 0->0.4pi");

                    if (d < 50 || d > 200)
                    {
                        MessageBox.Show("Độ dài thanh không phù hợp 50->200m");
                    }
                }
                else
                {
                    if (GetMyValue != null)
                        GetMyValue(tbxGocNghieng.Text, tbxChieuDai.Text, true);
                }

            }
                
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (GetMyValue2!=null)
            {
                GetMyValue2(true);
            }
            this.Close();
        }

        private void tbxGocNghieng_KeyPress(object sender, KeyPressEventArgs e)
        {
            string decimalString = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            char decimalChar = Convert.ToChar(decimalString);

            if (Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)) { }
            else if (e.KeyChar == decimalChar && tbxGocNghieng.Text.IndexOf(decimalString) == -1)
            { }
            else
            {
                e.Handled = true;
            }
        }

        private void tbxChieuDai_KeyPress(object sender, KeyPressEventArgs e)
        {
            string decimalString = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            char decimalChar = Convert.ToChar(decimalString);

            if (Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)) { }
            else if (e.KeyChar == decimalChar && tbxChieuDai.Text.IndexOf(decimalString) == -1)
            { }
            else
            {
                e.Handled = true;
            }
        }

    }
}
